package
{
	import flash.display.InteractiveObject;
	import flash.events.KeyboardEvent;

	public class CarKeyboard implements ICarInputSet
	{
		private var _isLeft:Boolean;
		private var _isRight:Boolean;
		private var _isUp:Boolean;
		private var _isDown:Boolean;
		private var _isDrifting:Boolean;
		private var interactiveObject:InteractiveObject;
		public function CarKeyboard(interactiveObject:InteractiveObject)
		{
			this.interactiveObject = interactiveObject;
			addEventListener();
		}
		public function addEventListener():void{
			interactiveObject.addEventListener(KeyboardEvent.KEY_DOWN,onKeyDown);
			interactiveObject.addEventListener(KeyboardEvent.KEY_UP,onKeyUp);
			
		}
		public function removeEventListener():void{
			interactiveObject.removeEventListener(KeyboardEvent.KEY_DOWN,onKeyDown);
			interactiveObject.removeEventListener(KeyboardEvent.KEY_UP,onKeyUp);
		}
		private function onKeyDown(event:KeyboardEvent):void{
			switch(event.keyCode){
				case 37:
					_isLeft=true;
					break;
				case 38:
					_isUp=true;
					break;
				case 39:
					_isRight=true;
					break;
				case 40:
					_isDown=true;
					break;
				case 16:
					_isDrifting=true;
					break;
			}
		}
		private function onKeyUp(event:KeyboardEvent):void{
			switch(event.keyCode){
				case 37:
					_isLeft=false;
					break;
				case 38:
					_isUp=false;
					break;
				case 39:
					_isRight=false;
					break;
				case 40:
					_isDown=false;
					break;
				case 16:
					_isDrifting=false;
					break;
			}
		}
		public function get isLeft():Boolean
		{
			return _isLeft;
		}
		
		public function get isRight():Boolean
		{
			return _isRight;
		}
		
		public function get isUp():Boolean
		{
			return _isUp;
		}
		
		public function get isDown():Boolean
		{
			return _isDown;
		}
		
		public function get isDrifting():Boolean
		{
			return _isDrifting;
		}
	}
}